import React, { Component } from 'react'
import PubSub from 'pubsub-js'
import axios from 'axios'
export default class search extends Component {
    render() {
        return (
            <div>
                <input type="text" ref={c => this.searchValue = c} />
                <button onClick={this.search}>搜索</button>
            </div>
        )
    }
    search = async () => {
        let { searchValue: { value: searchMsg } } = this //连续解构赋值
        // // 发送请求前通知List更新状态
        PubSub.publish('atguigu',{ isFirst: false, isloding: true })
        // // 发送网络请求
        axios.get(`https://api.github.com/search/users?q=${searchMsg}`).then(res => {
        PubSub.publish('atguigu',{users:res.data.items,isloding:false})
        }).catch(err=>{
        PubSub.publish('atguigu',{isloding:false,err:err.message})
        })
    }
}
